# Created by 黄景涛
# DATE 2024/5/16
import requests
from faker import Faker
from requests import Session
from datetime import datetime
import jsonpath库
import random
from user_login.login_ import login
from organizations_and_users.settings import create_organization
from organizations_and_users.create_users import engine
from utils.yaml_util import read_yaml
from acmdb.cmdb_object import *

cfg_info = read_yaml()
fk = Faker(locale='zh_CN')


def main():
    session = requests.Session()
    # 手动填写登录信息
    cookies = "bk_token=vFrAcbCNF3bDImdg7NysMXQEQJs8vqFooQJBvNjp28w; blueking_language=zh-cn; bklogin_csrftoken=hFDGDFnAJeOf8ybJsCVxDTFiz7KV8XLHoD5mvRZrCZYr3IyDuA48VRunO06M4PKH; sessionid=02puhd84ndcxfct3apvmrzq9czsta34d; csrftoken=nfERi3LubcSTW0SVZjoGXkodPPR4rOG6EEOpDIlTNHf2mQ8tyl8zGlpred3iqvio; esmv35_saas_sessionid=jgxrknsorowbsbdsqe0h8tor05txkndt; recently_portal_id=1; bkitsm_csrftoken=ykSZu97PRw8bnSmvZapUBDocgaWLhQGYykRQWghxRApxKSYtgOrlWlLORGSQ5uvq; _sessionid=eryavp8idwfvixm2gb636ragxkydtvo7; cc-portal_saas_csrftoken=tG1Kn5IbkvpLtnGajSKBSsTkCf8Cp1C3fVMAClsDOy9j5aQ98WhcE4pjHAYKtVNB; cc-portal_saas_sessionid=3vtb0038sl1tt9lnovk8lwh8d34qjluq"
    token = "KiUbxlrARIEQ7eaKcnDOnIGGbe9LtY2DwxF1MBb2lLooJ1kJ1rap9kcFgzZTxSdb"
    global_headers = {
        "User-Agent": fk.user_agent(),
        "Cookie": cookies,
        "X-Csrftoken": token
    }

    # 1.登录,返回已登录的session对象
    # cookies, token = login()
    # global_headers = {
    #     "User-Agent": fk.user_agent(),
    #     "Cookie": cookies,
    #     "X-Csrftoken": token
    # }

    # 2. 创建组织和用户
    # root = create_organization()
    # engine(cookies, token, root)
    # TODO 3.创建用户组
    # TODO 4.创建cmdb角色

    # 5.cmdb模型（通用模型）
    group = HJTModelGroup(session, global_headers)
    group.create()      # 创建
    newest_group_id = group.hjt_groups[-1]
    model = HJTModel(newest_group_id, session, global_headers)
    depth = 5       # 模型个数（也是实例拓扑的层数）
    for i in range(depth):
        model.create()
        model.add_attrs()
        print(f'创建的模型: {model.hjt_objects}')

    ''' complex: 链条式的关联 '''
    model.add_asst_by_chain()
    # 6.创建对应的实例、添加关联关系（通用模型）
    for i in range(1):
        model.add_insts_by_tree(depth=depth)

    # ''' simple: 以一个模型为中心，发散的关联 '''
    # model.add_asst_by_center()
    # model.add_insts_by_simple(inst_count=2)


if __name__ == '__main__':
    main()
